#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

use std::fs;
#[tauri::command]
fn save_data(contents: &str) -> i32{
    match fs::write("data.json", contents) {
        Ok(_) => 0,
        Err(e) => {
            eprintln!("{}", e.to_string());
            1
        }
    }
}

#[tauri::command]
fn load_data() -> String {
    match fs::read_to_string("data.json") {
        Ok(contents) => contents,
        Err(e) => {
            eprintln!("{}", e.to_string());
            "[]".to_string()
        },
    }
}


fn main() {
    tauri::Builder::default()
        .invoke_handler(tauri::generate_handler![save_data, load_data])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
